package com.mms.utsc.smartnet;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;

class User {
	
	int userID;
	String name;
	String username;
	//String passwordMD5;
	ArrayList<Announcement> announcements;
	ArrayList<MenuListItem> courses;

	public User(int userId, String username, String name){
		this.username = username;
		this.name = name;
		this.userID = userId;
		//this.passwordMD5 = User.convertPasswordToMD5(password);
		
	}
	
	void setCourses(ArrayList<MenuListItem> courses) {
		this.courses = courses;
	}
	
	String getName() {
		return name;
	}

	String getUsername() {
		return username;
	}

	/*String getPasswordMD5() {
		return passwordMD5;
	}*/
	
	String getCourseName() {
		String courseName = "";
		for(int i=0; i < courses.size(); i++) {
			courseName += courses.get(i).getMenuItemText() + "|";
		}
		return courseName.substring(0,courseName.length() - 1);
	}
	
	private static String convertPasswordToMD5(String password){
		MessageDigest digester = null;
		try {
			digester = MessageDigest.getInstance("md5");
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        digester.reset();
        digester.update(password.getBytes());
        byte messageDigest[] = digester.digest();

        StringBuffer hexString = new StringBuffer();
        String tmp;
        for (int i = 0; i < messageDigest.length; i++) {
            tmp = Integer.toHexString(0xFF & messageDigest[i]);
            if (tmp.length() == 1) {
                hexString.append("0");
            }
            hexString.append(tmp);
        }
      	return hexString.toString();
	}
}
